﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SHNOPData.common
{
    public class CommonUtil
    {
        /// <summary>
        /// 获取文件大小 eg:99.34GB /99.57MB /99.78KB
        /// </summary>
        /// <param name="size">文件的大小</param>
        /// <returns></returns>
        public static string GetFileSize(int size)
        {
            string FileSize = "";
            if (size != 0)
            {
                if (size >= 1073741824)
                {
                    FileSize = System.Math.Round(Convert.ToDouble((double)size / (double)1073741824), 2).ToString() + "GB";  //GB
                }
                else if (size >= 1048576)
                {
                    FileSize = System.Math.Round(Convert.ToDouble((double)size / (double)1048576), 2).ToString() + "MB";
                }
                else if (size >= 1024)
                {

                    FileSize = System.Math.Round(Convert.ToDouble((double)size / (double)1024), 2).ToString() + "KB";
                    int a = size / 1024 * 100;
                    int b = size / 1024;
                }
                else
                {
                    FileSize = size.ToString() + "bytes";
                }
            }
            else
            {
                FileSize = size.ToString() + "bytes";
            }
            return FileSize;
        }
    }
}
